<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld"%>
<!DOCTYPE html>
<html>
	<head>
		<title>字典值修改</title>
		<!-- 引入公用Js与Css -->
  		<%@include file="/view/common/resource.jsp" %>
	</head>
	<body>
		<div id="wrap">
			
			<div class="clearfix mt10 mr10 ml10">
				<form id="dictForm" class="form-horizontal" action="<%=basePath%>/sys/dict/addDictSave" method="post">
					<input type="hidden" name="id" value="${entity.id }">
					<input type="hidden" name="dictType" value="${entity.dictType }">
					<input type="hidden" name="dictTypeName" value="${entity.dictTypeName }">
					<dl class="ml10">
						
						<dd class="clearfix pt15">
							<label class="w80 mr10 pull-left text-right line-height30">字典值:</label>
							<div class="w300 input-group input-group-sm" >
					            <input type="text" class="form-control" id="dictValue" name="dictValue" value="${dictBase.dictValue }" placeholder="请填写一个字典值(必填项)">
							</div>
						</dd>
						
						<dd class="clearfix pt15">
							<label class="w80 mr10 pull-left text-right line-height30">字典名称:</label>
							<div class="w300 input-group input-group-sm" >
					            <input type="text" class="form-control" id="dictName" name="dictName" value="${dictBase.dictName }" placeholder="请填写字典名称(必填项)">
							</div>
						</dd>
						
						<dd class="clearfix pt30 ml110">
							<p class="radius3 bg_blue text-center w200 line-height30 mt10">
								<a href="javascript:" onclick="updateSave();" class="color_white show">
								<c:choose>
									<c:when test="${empty entity.id }">
										确认添加
									</c:when>
									<c:otherwise>
										确认更新
									</c:otherwise>
								</c:choose>
								</a>
							</p>
						</dd>
					</dl>
				</form>
			</div>
		</div>
		<script type="text/javascript">
	    var validate = null;
	    $(document).ready(function(){
	    	validate = $('#dictForm').validate({
	    		onkeyup:false,
				onfocusout: function(element){
					if (element.value != null && element.value != "") {
						$(element).valid();
					}
			    },
	    		rules:{
	    			dictValue:{
						required:true,
						lettersOrNumbers:true,
						remote:{
							url:'checkDict',
							type:'post',
							data:{
								dictValue:function(){return encodeURI(encodeURI($("#dictValue").val()));},
								dictType:'${entity.dictType }',
								oldDictValue:'${dictBase.dictValue }'
							}
						}
					},
					dictName:{
						required:true,
						remote:{
							url:'checkDict',
							type:'post',
							data:{
								dictName:function(){return encodeURI(encodeURI($("#dictName").val()));},
								dictType:'${entity.dictType }',
								oldDictName:'${dictBase.dictName }'
							}
						}
					}
				},
				messages:{
					dictValue:{
						required:"请输入字典值",
						remote:"字典值已经存在"
					},
					dictName:{
						required:"请输入字典名称",
						remote:"字典名称已经存在"
					}
				},
				errorPlacement: function(error, element) {
					layer.tips(error.text(), '#'+element.attr("name"), {
					  tips: [2, '#78BA32']
					});
				}
			});
	    });
	    
    	/* 数据保存 */
	    function updateSave() {
    		
    		// 验证数据
	    	if (!validate.form()) {
	    		return false;
	    	}
	    	
    	    var actionurl=$('#dictForm').attr('action');//提交路径
    	    
    	    $("#dictForm").ajaxSubmit({
    	    	type:"post",
    	    	url:actionurl,
    	    	dataType: "json",
    	    	success:function(data){
        	    	if (data.success) {
    	   	        	// 成功后跳转首页
    	   	            layer.msg("操作成功", {icon: 6, time:1000}, function() {
    	   	            	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    	   	            	parent.layer.close(index);
    	   	            });
    	   	        } else {
    	   	      		// 失败提醒
    	   	        	layer.msg(data.msg, {icon: 5});
    	   	        }
       	    	}
    	    }); 
	    }
    </script>
	</body>
</html>
